<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>获取数据</button>
    <script>
        function callbackFunction(data){
            console.log(data);
        }
        
        const btn = document.querySelector("button")
        let newScript;
        btn.onclick = function(){
            if(newScript){
                return;
            }
            /* 使用script的src解决跨域的方式 => JSONP */
            newScript = document.createElement("script")
            //给script的script标签赋值 跨域的
            newScript.src = "https://www.runoob.com/try/ajax/jsonp.php?jsoncallback=callbackFunction"
            //扔到body里面
            document.body.appendChild(newScript);
        }
    </script>
</body>
</html>